<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>WLog: WLogInterface.cpp源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- 制作者 Doxygen 1.5.8 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="namespaces.html"><span>名字空间</span></a></li>
      <li><a href="annotated.html"><span>类</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>文件列表</span></a></li>
      <li><a href="globals.html"><span>文件成员</span></a></li>
    </ul>
  </div>
<h1>WLogInterface.cpp</h1><a href="WLogInterface_8cpp.html">浏览该文件的文档。</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="preprocessor">#include "<a class="code" href="WLogInterface_8h.html">WLogInterface.h</a>"</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include "<a class="code" href="Common_8h.html">Common.h</a>"</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="keyword">namespace </span>WLog
<a name="l00008"></a>00008 {
<a name="l00009"></a><a class="code" href="namespaceWLog.html#4eef0f756406a40b36699c3f95c5270e">00009</a>     <span class="keywordtype">bool</span> <a class="code" href="namespaceWLog.html#4eef0f756406a40b36699c3f95c5270e">bTrimFileName</a> = 0;
<a name="l00010"></a>00010 
<a name="l00011"></a><a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa">00011</a>     <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a> = 0;
<a name="l00012"></a>00012     
<a name="l00013"></a><a class="code" href="namespaceWLog.html#4c90989d4645c6ecd9d9113c3dc64fcd">00013</a>     <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* <a class="code" href="namespaceWLog.html#4c90989d4645c6ecd9d9113c3dc64fcd" title="设置log指针.">setLog</a>(<a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* pLog)
<a name="l00014"></a>00014     {
<a name="l00015"></a>00015         <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* pBak = <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a>;
<a name="l00016"></a>00016         <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a> = pLog;
<a name="l00017"></a>00017         <span class="keywordflow">return</span> pBak;
<a name="l00018"></a>00018     }
<a name="l00019"></a>00019 
<a name="l00020"></a><a class="code" href="namespaceWLog.html#88d869c121c4e8992922002033ac06c6">00020</a>     <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* <a class="code" href="namespaceWLog.html#88d869c121c4e8992922002033ac06c6" title="获取log指针.">getLog</a>()
<a name="l00021"></a>00021     {
<a name="l00022"></a>00022         <span class="keywordflow">return</span> <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a>;
<a name="l00023"></a>00023     }   
<a name="l00024"></a>00024     
<a name="l00025"></a><a class="code" href="namespaceWLog.html#251ca1d97c3062af94fc5471724dd6a1">00025</a>     <a class="code" href="classWLog_1_1IOuter.html" title="Interface for output Record with define Log Level.">IOuter</a>* <a class="code" href="namespaceWLog.html#251ca1d97c3062af94fc5471724dd6a1" title="设置log的输出outer指针.">setOuter</a>(<a class="code" href="classWLog_1_1IOuter.html" title="Interface for output Record with define Log Level.">IOuter</a> *pOuter)
<a name="l00026"></a>00026     {
<a name="l00027"></a>00027         assert(<a class="code" href="namespaceWLog.html#88d869c121c4e8992922002033ac06c6" title="获取log指针.">getLog</a>());
<a name="l00028"></a>00028         <span class="keywordflow">return</span> <a class="code" href="namespaceWLog.html#88d869c121c4e8992922002033ac06c6" title="获取log指针.">getLog</a>()-&gt;<a class="code" href="classWLog_1_1ILogProcess.html#ce3c7d8721cd6e40d2e4ae22504f5df5" title="设置类的输出对象IOuter.">setOuter</a>(pOuter);
<a name="l00029"></a>00029     }
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="namespaceWLog.html#620aeb437d19cc9051eba3c2b1cfbc03">00031</a>     <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* <a class="code" href="namespaceWLog.html#620aeb437d19cc9051eba3c2b1cfbc03" title="设置log与log的outer指针.">setOuterLog</a>(<a class="code" href="classWLog_1_1IOuter.html" title="Interface for output Record with define Log Level.">IOuter</a> *pOuter, <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* pLog)
<a name="l00032"></a>00032     {
<a name="l00033"></a>00033         <a class="code" href="classWLog_1_1ILogProcess.html" title="Interface for process the logs.">ILogProcess</a>* pBak = <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a>;
<a name="l00034"></a>00034         <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a> = pLog;
<a name="l00035"></a>00035         assert(!<a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a>-&gt;<a class="code" href="classWLog_1_1ILogProcess.html#ce3c7d8721cd6e40d2e4ae22504f5df5" title="设置类的输出对象IOuter.">setOuter</a>(pOuter));
<a name="l00036"></a>00036         <span class="keywordflow">return</span> pBak;
<a name="l00037"></a>00037     }
<a name="l00038"></a>00038 
<a name="l00039"></a><a class="code" href="namespaceWLog.html#121adb4c1a83fb9272cc01323d4da656">00039</a>     <span class="keywordtype">bool</span> <a class="code" href="namespaceWLog.html#121adb4c1a83fb9272cc01323d4da656" title="设置log的输出级别.">setOutLevel</a>(<span class="keywordtype">int</span> iOutLevel <span class="comment">/*= W_LEVEL_FLOOR*/</span>)
<a name="l00040"></a>00040     {
<a name="l00041"></a>00041         <span class="keywordflow">if</span> (<a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a>)
<a name="l00042"></a>00042         {
<a name="l00043"></a>00043             <a class="code" href="namespaceWLog.html#13b8ff10caf2fabc88a615041f44d6fa" title="全局变量 ILogProcess 指针,使得所有的log操作都使用一个实例">log</a>-&gt;<a class="code" href="classWLog_1_1ILogProcess.html#035c1a508ac1492b9344a510e317f668" title="设置输出级别.">setOutLevel</a>(iOutLevel);
<a name="l00044"></a>00044             <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00045"></a>00045         }
<a name="l00046"></a>00046         
<a name="l00047"></a>00047         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00048"></a>00048     }
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="namespaceWLog.html#14984727b0b46ea36398e5ebac29ef56">00050</a>     <span class="keywordtype">bool</span> <a class="code" href="namespaceWLog.html#14984727b0b46ea36398e5ebac29ef56" title="设置输出日志中，是否只保留文件名，而不要路径.">setTrimFileName</a>(<span class="keywordtype">bool</span> bTrim)
<a name="l00051"></a>00051     {
<a name="l00052"></a>00052         <span class="keywordtype">bool</span> bRet = <a class="code" href="namespaceWLog.html#4eef0f756406a40b36699c3f95c5270e">bTrimFileName</a>;
<a name="l00053"></a>00053         <a class="code" href="namespaceWLog.html#4eef0f756406a40b36699c3f95c5270e">bTrimFileName</a> = bTrim;
<a name="l00054"></a>00054         <span class="keywordflow">return</span> bRet;
<a name="l00055"></a>00055     }
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="namespaceWLog.html#157286d8013463871f20a6bfb039cac1">00057</a>     <span class="keywordtype">string</span> <a class="code" href="namespaceWLog.html#157286d8013463871f20a6bfb039cac1" title="以当前的时间创建文件名">buildFileNameNow</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* szPrefix <span class="comment">/*= ""*/</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* szEnd <span class="comment">/*= ".log"*/</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* szFormatDateTime <span class="comment">/*= "%Y-%m-%d_%H%M%S"*/</span>)
<a name="l00058"></a>00058     {
<a name="l00059"></a>00059 <span class="preprocessor">#define _TIME_MAX_BUF_SIZE 256</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span>        <span class="keywordtype">char</span>* pBuf = <span class="keyword">new</span> <span class="keywordtype">char</span>[<a class="code" href="WLogInterface_8cpp.html#dd2ffd6a404de46484834c18e80382e5">_TIME_MAX_BUF_SIZE</a>];
<a name="l00061"></a>00061         time_t time = <a class="code" href="namespaceWLog.html#bde42e02b00d5bd21cba645298573f19">now_time_t</a>();
<a name="l00062"></a>00062 <span class="preprocessor">#ifdef MORE_AND_EQUAL_THAN_VC8_VS2005</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span>        tm timeinfo = {0};
<a name="l00064"></a>00064         localtime_s(&amp;timeinfo, &amp;time);
<a name="l00065"></a>00065         tm* tLocalTime = &amp;timeinfo;
<a name="l00066"></a>00066 <span class="preprocessor">#else</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span>        tm* tLocalTime = localtime(&amp;time);
<a name="l00068"></a>00068 <span class="preprocessor">#endif // MORE_AND_EQUAL_THAN_VC8_VS2005</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span>
<a name="l00070"></a>00070         strftime(pBuf, <a class="code" href="WLogInterface_8cpp.html#dd2ffd6a404de46484834c18e80382e5">_TIME_MAX_BUF_SIZE</a>, szFormatDateTime, tLocalTime);
<a name="l00071"></a>00071         
<a name="l00072"></a>00072         <span class="keywordtype">string</span> strRet = szPrefix;
<a name="l00073"></a>00073         strRet += pBuf;
<a name="l00074"></a>00074         strRet += szEnd;
<a name="l00075"></a>00075         <span class="keyword">delete</span> [] pBuf;
<a name="l00076"></a>00076         
<a name="l00077"></a>00077         <span class="keywordflow">return</span> strRet;
<a name="l00078"></a>00078     }
<a name="l00079"></a>00079 }
</pre></div></div>
<hr>
<address style="align: right;">
  Generated on Mon Apr 6 21:08:12 2009 for WLog by 韦体东<img src="logo.png" align="middle"/></address>
</body>
</html>
